<?php
class Pi
{

 public function createImage($huyhieu,$tuong,$name,$pos){

	$targetfile = 'temp/'.$name.".jpg"; 
	$photo = imagecreatefromjpeg($tuong); 
	$fotoW = imagesx($photo); 
	$fotoH = imagesy($photo); 
	$logoImage = imagecreatefrompng($huyhieu); 
	$logoW = imagesx($logoImage); 
	$logoH = imagesy($logoImage); 
	$photoFrame = imagecreatetruecolor($fotoW,$fotoH); 
	$dest_x = $fotoW - $logoW; 
	$dest_y = $fotoH - $logoH; 
	imagecopyresampled($photoFrame, $photo, 0, 0, 0, 0, $fotoW, $fotoH, $fotoW, $fotoH); 
	imagecopy($photoFrame, $logoImage, $dest_x, $dest_y, 0, 0, $logoW, $logoH); 
	imagejpeg($photoFrame, $targetfile,100);  
	imagedestroy($photoFrame);
	imagedestroy($photo);
	imagedestroy($logoImage);
	$images =imagecreatefromjpeg($targetfile);;	
	$color = imagecolorallocate($images,255,204,51); 
	$font_file = 'code/timesbd_0.ttf';
	imagettftext($images,17,0,175,75,$color,$font_file,$name);
	imagettftext($images,17,0,180,128,$color,$font_file,$pos);
	$imagesname = md5(uniqid(mt_rand(), true));
	imagejpeg($images,'images/'.$imagesname.'.jpg',100);
	unlink("temp/".$name.".jpg");
	return 'images/'.$imagesname.'.jpg';
 }
}
?>